package edu.tgc.service.teaching;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

import org.abyss.common.service.CommonCrudService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.tgc.entity.code.TbCodeEconomicType;
import edu.tgc.entity.student.TbClass;
import edu.tgc.entity.system.SysDept;
import edu.tgc.entity.teaching.Enroll;
import edu.tgc.repository.student.TbClassRepository;
import edu.tgc.repository.teching.EnrollRepository;
import edu.tgc.security.SessionUserUtils;
@Service
public class EnrollService extends CommonCrudService<Enroll, UUID> {

	@Autowired
	private EnrollRepository enrollDAO;
	@Autowired
	private TbClassRepository classDAO;
	
	public List<HashMap<String, Object>> combo() {
		Date now=new Date();
		List<Enroll> list=enrollDAO.findByEndTimeGreaterThan(now);
		/*List<TbClass> bjs=getClasses();
		List<Enroll> list1=new ArrayList<>();
		for (Enroll enroll2 : list) {
			boolean flag=true;
			for (TbClass bj : bjs) {
				if(bjindept(bj, enroll2.getDept())){
					flag=false;
					break;
				}
			}
			if(flag){
				list1.add(enroll2);
			}
		}
		list.removeAll(list1);*/
		List<HashMap<String, Object>> maps=new ArrayList<>();
		for (Enroll enroll : list) {
			HashMap<String, Object> map=new HashMap<>();
			map.put("id", enroll.getId());
			map.put("text", enroll.getName());
			maps.add(map);
		}
		return maps;
	}
	
	public List<TbClass> getClasses(){
		UUID sysuserId = SessionUserUtils.getSysUser().getId();
		List<TbClass> list= classDAO.findByManagerId(sysuserId);
		return list;
	}
	
	public boolean bjindept(TbClass bj,SysDept dept){
		if(bj.getParentdept().getId().equals(dept.getId())){
			return true;
		}else if(bj.getParentdept().getParent().getId().equals(dept.getId())){
			return true;
		}else{
			return false;
		}
	}

}
